<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/10
  Time: 21:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>黄山学院-留学生信息管理系统</title>
    <link rel="stylesheet" href="/css/main_style.css">
    <script src="/js/main_function.js"></script>
    <script>
        // Ajax.post("/message/check",null,function (result) {
        //     // private Long user_id;
        //     // private String content;
        //     // private Date uptime;
        //     var results=JSON.parse(result);
        //     if(results.code=="100"){
        //         var data=results.data;
        //         var show="<table>";
        //         for(var i=0;data[i]!=null;i++){
        //             show =show+
        //                 "<tr>" +
        //                 "<td>用户 "+data[i].user_id+"：</td>" +
        //                 "<td>"+data[i].content+"</td>" +
        //                 "<td style='text-align: right'>发送时间："+data[i].uptime+"</td>" +
        //                 "</tr>"
        //         }
        //         show=show+"</table>";
        //         document.getElementById("message-model").innerHTML=show;
        //     }
        // });
        function checkUsers() {
            Ajax.post("/root/account/check", null, function callback(result) {
                var results = JSON.parse(result);
                if (results.code == "100") {
                    var data = results.data;
                    console.log(data);
                    console.log(results.data);
                    var show = "<table><tr><td>工号/学号</td><td>密码</td><td>身份</td></tr>";
                    for (var i = 0; data[i] != null; i++) {
                        if (data[i].identity == 9) {
                            continue;
                        }
                        show = show +
                            "<tr>" +
                            "<td>" + data[i].user_id + "</td>" +
                            "<td>" + data[i].password + "</td>";
                        if (data[i].identity == 1) {
                            show = show + "<td>学生</td>";
                        }
                        if (data[i].identity >= 5 && data[i].identity <= 7) {
                            show = show + "<td>教师</td>";
                        }
                        show = show + "</tr>";
                    }
                    show = show + "</table>";
                    document.getElementById("checkUsers").innerHTML = show;
                } else {
                    alert(results.msg);
                }
            });
        }

        function addUser() {
            Ajax.post("/root/account/add", formJson("addUser"), function callback(result) {
                var results = JSON.parse(result);
                if (result.code == "100") {
                    alert(results.msg);
                } else {
                    alert(results.msg);
                }
            });

        }

        function addUsers() {
            Ajax.post("/root/account/adds", formJson("addUsers"), function callback(result) {
                var results = JSON.parse(result);
                if (result.code == "100") {
                    alert(results.msg);
                } else {
                    alert(results.msg);
                }
            });
        }

        function delUser() {
            Ajax.post("/root/account/delete", formJson("delUser"), function callback(result) {
                var results = JSON.parse(result);
                if (result.code == "100") {
                    alert(results.msg);
                } else {
                    alert(results.msg);
                }
            });
        }

        function delUsers() {
            Ajax.post("/root/account/deletes", formJson("delUsers"), function callback(result) {
                var results = JSON.parse(result);
                if (result.code == "100") {
                    alert(results.msg);
                } else {
                    alert(results.msg);
                }
            });
        }
        function setUserInformation() {
            let form=document.getElementById("setUserInformation");
            let data=new FormData(form);
            Ajax.postFile("/root/account/setUserInformation",data,function (result) {
                let results=JSON.parse(result);
                if(results.code==100){
                    alert("数据导入成功！")
                }else {
                    alert(results.msg)
                }
            })
        }
    </script>
</head>
<body>
<div id="navigation">
    <div class="navigation-left"><img src="/img/school.png" style="width: 170px;height: 60px;"></img></div>
    <div class="navigation-center"><a>首页</a></div>
    <div class="navigation-right">
        <div class="drop-menu" style="float:right;">
            <div class="user-menu"></div>
            <div class="drop-menu-content">
                <a href="/logout">注销登录</a>
                <a href="/rePassword">修改密码</a>
            </div>
        </div>
    </div>
</div>
<div id="broadside">
    <div class="broadside-logo">
    </div>
    <div class="broadside-menu">
    </div>
</div>
<div  style="width: 70%;background-color: #FFFFFF;margin-right: 10%;float: right;padding-top: 60px;">
    <p>批量创建一个区间内的账号（请注意输入的两个数之差不要超过50）id前缀是自动添加在数字之前的</p>
    <form id="addUsers">
        <p>id前缀：<input type="text" name="id_head" value=""/></p>
        <p>起始id:<input type="text" name="begin_id" value=""/></p>
        <p>结束id:<input type="text" name="end_id" value=""/></p>
        <p>初始密码:<input type="text" name="password" value=""/></p>
        <p>选择创建账户类型:<input type="radio" name="identity" value="1" checked="checked">学生<input type="radio" name="identity" value="5">教师</p>
    </form>
    <button type="button" onclick="addUsers()"> 确认创建</button>

    <div style="width: 100%;height: 3px;margin-top: 30px;margin-bottom: 15px;border-bottom:1px dashed #000000;border-top: 1px dashed #000000"></div>
    <p>导入学生账户信息，若无学生学号将自动创建（建议用这种方式创建并写入学生信息， 避免学生账户重复）</p>
    <form id="setUserInformation" enctype="multipart/form-data">
        <p>请上传包含学生基本信息表(必须包括学生)的excel表格<br>(其中日期格式设置，支持excel的自带日期设置，<br>以及2021.8.25或者2021年8月25日的形式):<input type="file" name="information" value=""/></p>
    </form>
    <button type="button" onclick="setUserInformation()">提交</button>

    <div style="width: 100%;height: 3px;margin-top: 30px;margin-bottom: 15px;border-bottom:1px dashed #000000;border-top: 1px dashed #000000"></div>
    <p>创建一个新的账号（推荐按学号 ）</p>
    <form id="addUser">
        <p>id:<input type="text" name="creat_id" value=""/></p>
        <p>初始密码:<input type="text" name="password" value=""/></p>
        <p>选择创建账户类型：
            <input type="radio" name="identity" value="1" checked="checked" />学生
            <input type="radio" name="identity" value="5"/>教师
        </p>
    </form>
    <button type="button" onclick="addUser()"> 确认创建</button>

    <div style="width: 100%;height: 3px;margin-top: 30px;margin-bottom: 15px;border-bottom:1px dashed #000000;border-top: 1px dashed #000000"></div>
    <p>批量删除一个区间内的全部账号,id前缀是自动添加在数字之前的,id前缀＋数字为账户</p>
    <form id="delUsers">
        <p>id前缀：<input type="text" name="id_head" value=""/></p>
        <p>起始id:<input type="text" name="begin_id" value=""/></p>
        <p>结束id:<input type="text" name="end_id" value=""/></p>
    </form>
    <button type="button" onclick="delUsers()"> 确认删除</button>

    <div style="width: 100%;height: 3px;margin-top: 30px;margin-bottom: 15px;border-bottom:1px dashed #000000;border-top: 1px dashed #000000"></div>
    <p>删除某个账号</p>
    <form id="delUser">
        <p>输入删除账号的id：（学号/工号）<input type="text" name="user_id" value=""></p>
    </form>
    <button type="button" onclick="delUser()">点击删除</button>

    <div style="width: 100%;height: 3px;margin-top: 30px;margin-bottom: 15px;border-bottom:1px dashed #000000;border-top: 1px dashed #000000"></div>
    <p>查看系统当前所有账号</p>
    <form id="checkUsers">
        <p>==================</p>
    </form>
    <button type="button" onclick="checkUsers()">点击查看</button>
    <div style="height: 50px"></div>
</div>
</body>
</html>

